import Cookies from 'js-cookie'
import JsEncrypt from 'jsencrypt'

const TokenKey = 'py_admin_token'
const XsrfKey = '_xsrf'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getXsrftoken() {
  return Cookies.get(XsrfKey)
}

export function setXsrftoken(val) {
  return Cookies.set(XsrfKey, val)
}

/**
 * RSA加密
 * @param {*公钥} publicKey
 * @param {*密码} password
 */
export function getRSApassword(publicKey, password) {
  const jse = new JsEncrypt()
  jse.setPublicKey(publicKey)
  const res = jse.encrypt(password)
  return res
}
